﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test1
{
    public partial class Form11 : Form
    {
        public Form11()
        {
            InitializeComponent();
        }
        //01
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                object obj = null;
                int i = (int)obj;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        //02
        private void button2_Click(object sender, EventArgs e)
        {
            string str = "零基础学";
            int i = 0;
            try
            {
                i = Convert.ToInt32(str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                MessageBox.Show("程序执行完毕...");
            }
        }
        //03
        private void button3_Click(object sender, EventArgs e)
        {
            int int1, int2, num;
            try
            {
                int1 = 20;
                int2 = 0;
                if (int2 == 0)
                    throw new DivideByZeroException();
                num = int1 / int2;
            }catch(DivideByZeroException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        
    }
}
